﻿@using SWGeneracionE.Models;

<ul class="menu">
    @{
        List<webpages_Menu> menuList = ViewBag.Menu;
        if ((Request.IsAuthenticated) && (menuList !=null) ){
            
            foreach (SWGeneracionE.Models.webpages_Menu mp in menuList.Where(p=> p.Padre == 0)) {
                if(mp.Visible){
                    @:<li>@Html.ActionLink(mp.Nombre, mp.Accion, mp.Controlador)
                    if (menuList.Where(p=> p.Padre == mp.IdMenu).Count() > 0) {
                        @:<ul>
                        @RenderMenuItem(menuList,mp)
                        @:</ul>
                    }
                    @:</li>
                }
            }
        }
      }
</ul>
        
@helper RenderMenuItem(List<webpages_Menu> menuList, webpages_Menu mi) {
    foreach (webpages_Menu cp in menuList.Where(p=> p.Padre == mi.IdMenu))
    {
        if(cp.Visible){
            @:<li>
                @Html.ActionLink(cp.Nombre, cp.Accion, cp.Controlador)
                if (menuList.Where(p=> p.Padre == cp.IdMenu).Count() > 0) {
                    @:<ul> 
                        @RenderMenuItem(menuList, cp)
                    @:</ul>
                }else{
                    @:</li>
                }
            @:</li>
        }
    }
}